package com.mhz.widgets.client;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.mhz.widgets.client.filtertextbox.Filter.RemoveFilterHandler;
import com.mhz.widgets.client.filtertextbox.FilterTextBox;
import com.mhz.widgets.client.multicombo.MultiComboList.MultiComboSelectHandler;
import com.mhz.widgets.client.multicombo.MultiComboWidget;
import com.mhz.widgets.shared.MultiComboItem;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GWTWidgets implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	@Override
	public void onModuleLoad() {
		List<MultiComboItem> items = new ArrayList<MultiComboItem>();
		items.add(new MultiComboItem("item1", "Filtre 1"));
		items.add(new MultiComboItem("item2", "Filtre 2"));
		items.add(new MultiComboItem("item3", "Filtre 3"));
		items.add(new MultiComboItem("item4", "Filtre 4"));
		items.add(new MultiComboItem("item5", "Filtre 5"));
		items.add(new MultiComboItem("item6", "Filtre 6"));
		items.add(new MultiComboItem("item7", "Filtre 7"));
		items.add(new MultiComboItem("item8", "Filtre 8"));
		items.add(new MultiComboItem("item9", "Filtre 9"));

		final FilterTextBox filterTB = new FilterTextBox();

		final MultiComboWidget multiCombo = new MultiComboWidget("Add filters", "130px");
		multiCombo.setComboItems(items);

		// Add selection handler
		multiCombo.addSelectHandler(new MultiComboSelectHandler() {
			@Override
			public void onSelectItems(Set<MultiComboItem> items) {
				filterTB.removeAllFilters();
				for (MultiComboItem item : items) {
					filterTB.addFilter(item.getValue());
				}
			}
		});
		// Add remobe filter handler
		filterTB.setRemoveFilterHandler(new RemoveFilterHandler() {
			@Override
			public void onRemoveFilter(String filterName) {
				multiCombo.removeItem(filterName);
			}
		});

		HorizontalPanel panel = new HorizontalPanel();
		panel.add(filterTB);
		panel.add(multiCombo);

		RootPanel.get().add(panel);
	}
}
